package com.xyebank.ledger.service.sjdzadd.adaper;

import java.util.Date;

import com.xyebank.ledger.util.DateConverter;
import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LRepaymentInf;
import com.xyebank.ledger.service.common.conveter.RePayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.vo.deal.ZADDSjdCashRepayVo;

@Component(value = "zaddSjdRepayBeanConverter")
public class ZADDSjdRepayBeanConverter implements RePayBeanConverter<ZADDSjdCashRepayVo> {

	ModelMapper modelMapper = new ModelMapper();

	// 不能采取注入方式
	private DateConverter dateConverter = new DateConverter();

	class NXApplyPropertyMap extends PropertyMap<ZADDSjdCashRepayVo, LRepaymentInf> {
		// 注意 不要有重复的映射，不然会报错
		protected void configure() {
			// 手机号码
			map(source.getMblNO(), destination.getMblNo());
			// 享宇订单号
			map(source.getSsjloanno(), destination.getXyOrderNo());
			// 机构订单号
			map(source.getuid(), destination.getOrgOrderNo());
			// 本期应还本金
			map(source.getRepayPrincipal(), destination.getPayPrincipal());
			// 本期应还利息
			map(source.getRepayInterest(), destination.getPayInterest());
			// 本期应还服务费
			map(source.getRepayServiceFee(), destination.getPayServerFee());
			// 本期应还违约金
			map(source.getRepayLateFee(), destination.getPayPenalty());
			// 本期还款时间
			map(source.getActuRepayDate(), destination.getRepayTime());
			// 实际还款金额
			map(source.getActuRepayTotalAmt(), destination.getRepayAmount());
			// 结清状态
			// map(source.getRepayStatus(), destination.getStatus());
		}
	}

	public ZADDSjdRepayBeanConverter() {
		modelMapper.addMappings(new NXApplyPropertyMap());
	}

	@Override
	public LRepaymentInf covert(ZADDSjdCashRepayVo x) {
		LRepaymentInf entity = modelMapper.map(x, LRepaymentInf.class);
		entity.setDataSource("xyb01");
		entity.setXyOrgNo(ProductConstant.ZADD_LOAN_ORG);
		entity.setXyProductNo(ProductConstant.ZADD_PROD_ID);
		entity.setId(IDUtil.generateId(x.getpid(), "zadd_sjd_repay"));
		String status = x.getRepayStatus();
		if("未到期".equals(status)){
			entity.setStatus(CommonConstant.REPAY_ING);
		}else if ("已还清".equals(status)) {
			entity.setStatus(CommonConstant.REPAY_CLEAR);
		}else if ("未还清".equals(status) || "支付失败".equals(status)) {
			entity.setStatus(CommonConstant.REPAY_UNCLEAR);
		}else if ("已逾期".equals(status)) {
			entity.setStatus(CommonConstant.REPAY_OVER);
		}else if ("处理中".equals(status)) {
			entity.setStatus(CommonConstant.REPAY_OVER_CLEAR);
		}
		return entity;
	}
}
